﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ViewableRangeTriangle : MonoBehaviour
{
    public float radius = 0;
    public int part = 90;
    public float angle = 0;
    private Collider2D myCollider;

    void Awake()
    {
        myCollider = gameObject.GetComponent<PolygonCollider2D>();
    }

    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        float deepth = radius;
        var t = Physics2D.CircleCast(transform.position,
            0.01f,
            Quaternion.Euler(new Vector3(0, 0, angle)) * new Vector3(1f, 0, 0),
            deepth,
            LayerMask.GetMask("Cube", "Mask"));
        if (t.transform != null)
        {
            deepth = Function.DistanceIgnoreZ(t.point, transform.position);
        }
        transform.localScale = new Vector3(deepth, deepth * Mathf.Sin(180f / part * Mathf.Deg2Rad) * 2, 1);
    }
}